const sass = require('sass')
const loadGruntTasks = require('load-grunt-tasks') 
module.exports = grunt => {
    grunt.initConfig({
        sass: {
            options: {
                sourceMap: true,
                implementation: sass
            },
            main: {
                files: {
                    // 目标路径：源路径
                    'dist/css/main.css': 'src/scss/main.scss'
                }
            }
        },
        babel: {
            // 设置babel在转换的时候的那个preset
            options: {
                sourceMap: true,
                presets: ['@babel/preset-env']
            },
            main: {
                files: {
                    'dist/js/app.js': 'src/js/app.js'
                }
            }
        },
        watch: {
            js: {
                files: ['src/js/*.js'],
                tasks: ['babel']
            },
            css: {
                files: ['src/scss/*.scss'],
                tasks: ['sass']
            }
        },
    })
    // 多目标任务
    // grunt.loadNpmTasks('grunt-sass')
    loadGruntTasks(grunt) // 会自动加载所有的插件中的任务

    // 给watch做一个映射
    grunt.registerTask('default', ['sass', 'babel', 'watch'])

}